# coding:utf-8
# @Time    : 2021/11/29 16:23
# @Author  : Martin

from page_object.base.page_items import PageItems


class PageItemsCarrefour(PageItems):

    def check_store_type(self, store_type_ids):
        """
        选择业态类型
        :param store_type_ids:
        """
        # 勾选部分门店
        self.single_checked('id', 'storeActRadio')
        store_type_ids = str(store_type_ids).split(',')
        for store_type in store_type_ids:
            self.single_checked('xpath', f'//input[@value="{store_type}"][@name="selectStore"]')

        # 点击全选添加到列表
        self.click('id', 'addalls4')

    def input_grant_scale(self, param):
        """
        输入家乐福承担比例
        :param param:
        :return:
        """
        self.input('name', 'limitCondition.grantScale', param)

    def input_per_count(self, param):
        """
        输入每会员每天参加次数
        :param param:day_
        :return:
        """
        self.input('name', 'limitCondition.perDayCount', param)

    def input_discount_single(self, params):
        """
        家乐福活动维护单品
        :param params:
        :return:
        """
        self.click('link text', '折扣商品范围')
        for param in params:
            # self.input('id', 'topDiscounts',param['discount'])
            # 获取优惠输入框
            discount = self.locate('id', 'topDiscounts')
            # 输入优惠
            self.add_attribute(discount, 'value', param['discount'])
            # 输入商品编码
            self.input('id', 'cmmdCodeDiscount', param['code'])
            # 点击添加到商品范围
            self.click('id', 'cmmdCodeAddDiscount')

    def add_single_jlf(self, txt):
        """
        添加家乐福单品包含
        :param txt:
        :return:
        """
        self._select_relation('包含')
        codes = str(txt).split(',')
        for code in codes:
            self._input_cmmd(code)
            self.click('id', 'cmmdCodeAdd')
        # self.click('link text', '添加到商品范围')

    def go_to_approve(self):
        """
        点击提交去审批
        :return:
        """
        self.click('id', 'evaluateSubmitBtn')

    def input_act_theme(self, txt):
        self.input('name','promotionMaster.activityTheme',txt)
